package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysWorkLogDiary;
import com.ruoyi.system.service.ISysWorkLogDiaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运行记事Controller
 * 
 * @author ruoyi
 * @date 2023-02-02
 */
@RestController
@RequestMapping("/system/diary")
public class SysWorkLogDiaryController extends BaseController
{
    @Autowired
    private ISysWorkLogDiaryService sysWorkLogDiaryService;

    /**
     * 查询运行记事列表
     */
    @PreAuthorize("@ss.hasPermi('system:diary:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysWorkLogDiary sysWorkLogDiary)
    {
        startPage();
        List<SysWorkLogDiary> list = sysWorkLogDiaryService.selectSysWorkLogDiaryList(sysWorkLogDiary);
        return getDataTable(list);
    }

    /**
     * 导出运行记事列表
     */
    @PreAuthorize("@ss.hasPermi('system:diary:export')")
    @Log(title = "运行记事", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysWorkLogDiary sysWorkLogDiary)
    {
        List<SysWorkLogDiary> list = sysWorkLogDiaryService.selectSysWorkLogDiaryList(sysWorkLogDiary);
        ExcelUtil<SysWorkLogDiary> util = new ExcelUtil<SysWorkLogDiary>(SysWorkLogDiary.class);
        return util.exportExcel(list, "diary");
    }

    /**
     * 获取运行记事详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:diary:query')")
    @GetMapping(value = "/{diaryId}")
    public AjaxResult getInfo(@PathVariable("diaryId") Long diaryId)
    {
        return AjaxResult.success(sysWorkLogDiaryService.selectSysWorkLogDiaryById(diaryId));
    }

    /**
     * 新增运行记事
     */
    @PreAuthorize("@ss.hasPermi('system:diary:add')")
    @Log(title = "运行记事", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWorkLogDiary sysWorkLogDiary)
    {
        return toAjax(sysWorkLogDiaryService.insertSysWorkLogDiary(sysWorkLogDiary));
    }

    /**
     * 修改运行记事
     */
    @PreAuthorize("@ss.hasPermi('system:diary:edit')")
    @Log(title = "运行记事", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWorkLogDiary sysWorkLogDiary)
    {
        return toAjax(sysWorkLogDiaryService.updateSysWorkLogDiary(sysWorkLogDiary));
    }

    /**
     * 删除运行记事
     */
    @PreAuthorize("@ss.hasPermi('system:diary:remove')")
    @Log(title = "运行记事", businessType = BusinessType.DELETE)
	@DeleteMapping("/{diaryIds}")
    public AjaxResult remove(@PathVariable Long[] diaryIds)
    {
        return toAjax(sysWorkLogDiaryService.deleteSysWorkLogDiaryByIds(diaryIds));
    }
}
